<template>
    <!-- <div class="wrapper"> -->
        <el-form :inline="true" label-width="20%">
            <template v-for="item in formList">
                <custom-form-item :formItem="item"></custom-form-item>
            </template>
        </el-form>
    <!-- </div> -->
</template>

<script>
    import {cloneDeep} from "lodash-es"
    import CustomFormItem from "./CustomFormItem.vue"
    export default {
        components:{
            CustomFormItem,
        },
        props:{
            list:{
                type:Array,
                default:function () {
                  return [];
                }
            },
        },
        watch:{
            list:{
                handler(val){
                    this.formList = cloneDeep(val)
                },
               immediate:true
            }
        },
        data(){
            return{
                formList:[]
            }
        },
        mounted() {

        },
        methods: {
            init(){
            },
            validate(){

            },
            gererateData(){
                const arr = JSON.parse(JSON.stringify(this.list))
                const formList = this.formList
                arr.forEach((item,index)=>{
                    const multiFlag = item.multiFlag
                    const val = formList[index].value
                    switch(item.fieldType){
                        case 1:
                            item.value = val
                            break
                        case 2:
                            item.value = val
                            if(multiFlag){
                                item.value = val.join(",")
                            }
                            break
                        case 3:
                            if(multiFlag){
                                const begin = this.$Utils.formatDate(val[0],"yyyy-MM-dd hh:mm:ss")||''
                                const end = this.$Utils.formatDate(val[1],"yyyy-MM-dd hh:mm:ss")||''
                                item.value = begin+","+end
                            }else{
                                item.value = this.$Utils.formatDate(val,"yyyy-MM-dd hh:mm:ss")||'';
                            }
                            break
                        case 4:
                            item.value = val.join(",")
                            break
                        case 5:
                            item.value = val
                            break
                        case 6:
                            item.value = val
                            break
                    }
                })
                return arr
            }
        },
    }
</script>

<style lang="scss" scoped>

</style>
